
import rules from './config/rules'
import {status, server} from './config/consts'

export default {

    install(Vue, options) {

        // 全局常量
        Vue.prototype.$status = status;
        Vue.prototype.$server = server;

        // 类型验证
        Vue.prototype.$rules = rules;

        // 自定义指令
        Vue.directive('switch', function (el, binding) {
            let {
                arg: argVal,
                value: lists,
            } = binding;
            // 查找要匹配的变量
            let result = lists.find(item => item.value == argVal);
            if (!result) el.textContent = '';
            else {
                let { before = '', after = '' } = el.dataset;
                let content = result.label || result.name || result.title;
                el.textContent = before.concat(content).concat(after);
            }
        })

        
        // 将函数库注册为filter
        Object.keys(utils).forEach(key => {
            Vue.filter(key, function (value, ...args) {
                if (utils[key] instanceof Function) {
                    // 将value作为第一个参数值，剩余参数分别传入方法中
                    return utils[key](value, ...args);
                }
            });
        });

    }

}